import { legacy_createStore as createStore, combineReducers, applyMiddleware } from 'redux';
import logger from 'redux-logger'
import { userReducer } from './user';

const reducer = combineReducers({
	userReducer: userReducer,
})

const store = createStore(reducer, applyMiddleware(logger))

// 订阅仓库
store.subscribe(() => {
	// 只要dispatch action 
	// 该回调函数会执行
	const state = store.getState()
	localStorage.setItem('role', state.userReducer.role)
	localStorage.setItem('nickname', state.userReducer.nickname)
	localStorage.setItem('token', state.userReducer.token)
	localStorage.setItem('avator', state.userReducer.avator)
})

export default store